#ifndef __STU_ENTITY2D__
#define __STU_ENTITY2D__
#include "Renderer.h"
#define PI_OVER180 0.01745294f

#define ____MIN_V 0.0f
#define ____MAX_V 1.0f

class ENGINE_API Entity2D
{
protected:
	virtual void resetVertexs() {}
	float posX, posY, posZ;
	float Height, Width;
	float rotX, rotY, rotZ;

public:
	bool visible;

	Entity2D()
	{
		Height = 10;
		Width = 10;
		posX = 10;
		posY = 10;
		posZ = 0;
		rotX = rotY = rotZ = 0;
		resetVertexs();
	}

	Entity2D(float xPos, float yPos)
	{
		Height = 10;
		Width = 10;
		posX = xPos;
		posY = yPos;
		posZ = 0;
		rotX = rotY = rotZ = 0;
		resetVertexs();
	}

	Entity2D(float xPos, float yPos, float height, float width)
	{
		Height = height;
		Width = width;
		posX = xPos;
		posY = yPos;
		posZ = 0;
		rotX = rotY = rotZ = 0;
		resetVertexs();
	}

	Entity2D(float xPos, float yPos, float height, float width, float rotX, float rotY, float rotZ)
	{
		Height = height;
		Width = width;
		posX = xPos;
		posY = yPos;
		posZ = 0;
		this->rotX = rotX; 
		this->rotY = rotY;
		this->rotZ = rotZ;
		resetVertexs();
	}

	float getLeft() { return posX;}
	float getTop() { return posY;}
	float getHeight() { return Height;}
	float getWidth() { return Width;}

	void setBounds(float top, float left, float height, float width)
	{
		posX = left;
		posY = top;
		Height = height;
		Width = width;
		resetVertexs();
	}
	void setPosition(float top, float left)
	{
		posX = left;
		posY = top;
		resetVertexs();
	}
	void setSize(float height, float width)
	{
		Height = height;
		Width = width;
		resetVertexs();
	}
	void setRotation(float x, float y, float z)
	{
		rotX = x;
		rotY = y;
		rotZ = z;
	}

	void setLeft(float left)
	{
		posX = left;
		resetVertexs();
	}
	void setTop(float top)
	{
		posY = top;
		resetVertexs();
	}
	void setWidth(float width)
	{
		Width = width;
		resetVertexs();
	}
	void setHeight(float height)
	{
		Height = height;
		resetVertexs();
	}
	void setRotationX(float x)
	{
		rotX = x;
	}
	void setRotationY(float y)
	{
		rotY = y;
	}
	void setRotationZ(float z)
	{
		rotZ = z;
	}

	virtual void Draw(Renderer* renderer)
	{
		renderer->setMatrixMode(Matrix_Mode::World);

		renderer->loadIdentity();
		
		if(rotX > 0.01f)
			renderer->RotateX(rotX * PI_OVER180);
		if(rotY > 0.01f)
			renderer->RotateY(rotY * PI_OVER180);
		//renderer->RotateZ(rotZ * PI_OVER180);
		renderer->Scale(Width, Height);
		renderer->Translate(posX,posY,posZ);
		/**
		renderer->graphCardHandle->SetTransform(D3DTS_VIEW, &renderer->viewerMatrix);
		renderer->graphCardHandle->SetTransform(D3DTS_PROJECTION, &renderer->projectionMatrix);/**/
	}
	virtual void Update() = 0;
};

#endif